package com.huike.web.controller.business;

import com.huike.business.domain.TbBusiness;
import com.huike.business.service.TbBusinessService;
import com.huike.clues.domain.vo.AssignmentVo;
import com.huike.common.annotation.Log;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: wwq
 * @Date: 2023/07/12/15:22
 * @Description:
 */
@RestController
@RequestMapping("/business")
@Slf4j
@Api(tags = "商机相关接口")
public class TbBusinessController extends BaseController {
    @Resource
    private TbBusinessService tbBusinessService;

    @ApiOperation("新增商机")
    @PostMapping
    @Log(title = "新增商机", businessType = BusinessType.INSERT)
    public AjaxResult<Integer> add(@RequestBody TbBusiness tbBusiness) {
        int rows = tbBusinessService.add(tbBusiness);
        return AjaxResult.success(rows);
    }

    @ApiOperation("查询商机列表")
    @GetMapping("/list")
    public TableDataInfo<List<TbBusiness>> list(TbBusiness tbBusiness) {
        List<TbBusiness> businessList=tbBusinessService.list(tbBusiness);
        return getDataTablePage(businessList);
    }

    @ApiOperation("修改商机")
    @GetMapping
    public AjaxResult<Integer> update(@RequestBody TbBusiness tbBusiness) {
        int rows = tbBusinessService.update(tbBusiness);
        return AjaxResult.success(rows);
    }

    @ApiOperation("商机分配")
    @PutMapping("/assignment")
    public AjaxResult<String> assignment(@RequestBody AssignmentVo assignmentVo) {
        String msg = tbBusinessService.assignment(assignmentVo);

        return AjaxResult.success(msg);
    }

    @ApiOperation("踢回公海")
    @PutMapping("/back/{id}/{reason}")
    public AjaxResult<Integer> back(@PathVariable Long id, @PathVariable String reason) {
        int rows = tbBusinessService.back(id,reason);

        return AjaxResult.success(rows);
    }

    @ApiOperation("批量捞取")
    @PutMapping("/gain")
    public AjaxResult<String> gain(@RequestBody AssignmentVo assignmentVo) {
        String msg = tbBusinessService.gain(assignmentVo);
        return AjaxResult.success(msg);
    }

    @ApiOperation("查询商机列表")
    @GetMapping("/pool")
    public TableDataInfo<List<TbBusiness>> pool(TbBusiness tbBusiness) {
        List<TbBusiness> list=tbBusinessService.pool(tbBusiness);
        return getDataTablePage(list);
    }
}
